Skip to content

Fix grant macros SQL quoting (v1.0.8)#35

Merged
jonhopper-dataengineers merged 1 commit into
mainfrom
fix/grant-sql-quoting
Jun 25, 2026
Merged

Fix grant macros SQL quoting (v1.0.8)#35
jonhopper-dataengineers merged 1 commit into
mainfrom
fix/grant-sql-quoting

Conversation

@jonhopper-dataengineers

@jonhopper-dataengineers jonhopper-dataengineers commented Jun 25, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixed SQL compilation error in grant macros where Jinja's tojson filter produced double-quoted strings ("ROLE_NAME") that Snowflake interprets as identifiers instead of string literals
  • Replaced map('tojson') with map("format", "'%s'") across 3 macro files (5 occurrences) to emit correct single-quoted SQL strings
  • Bumped version to 1.0.8, updated CHANGELOG and README

Test plan

  • Run dbt run-operation grant_schema_read against a schema with roles to confirm no invalid identifier errors
  • Run dbt run-operation grant_schema_object_privileges and verify generated SQL uses single-quoted role names
  • Verify _grants_get_schema_object_privs helper produces correct SQL in dry-run mode

.... Generated with Cortex Code

Summary by Sourcery

Fix SQL quoting in grant macros to ensure role and privilege names are emitted as single-quoted string literals and bump the package version to 1.0.8.

Bug Fixes:

  • Resolve SQL compilation errors in grant-related macros by correcting quoting of privilege types and grantees in generated Snowflake queries.

Enhancements:

  • Update package metadata and documentation to reflect the new 1.0.8 release with the grant SQL quoting fix.

Documentation:

  • Document the 1.0.8 release and its grant SQL quoting fix in the changelog and README version header.

… literals

The Jinja tojson filter wraps values in double quotes which Snowflake interprets as identifiers causing invalid identifier errors. Replaced with format to emit proper single-quoted SQL strings.

Bumped version to 1.0.8.

.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)

Co-Authored-By: Cortex Code <noreply@snowflake.com>
@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes SQL quoting in grant-related dbt macros by replacing Jinja tojson-generated double-quoted role/privilege strings with correctly single-quoted strings, and bumps the package version to 1.0.8 with corresponding docs/changelog updates.

Sequence diagram for corrected SQL quoting in grant macros

sequenceDiagram
    actor DbtUser
    participant DbtCli as dbt_cli
    participant GrantMacro as grant_schema_read
    participant Jinja as jinja_filters
    participant Snowflake

    DbtUser->>DbtCli: run-operation grant_schema_read
    DbtCli->>GrantMacro: render grant_schema_read
    GrantMacro->>Jinja: map("format", "'%s'") on grant_roles
    Jinja-->>GrantMacro: 'ROLE_A','ROLE_B'
    GrantMacro->>Snowflake: execute SQL with grantee not in ('ROLE_A','ROLE_B')
    Snowflake-->>DbtCli: success (no invalid identifier error)
Loading

File-Level Changes

Change Details Files
Ensure grant-related macros emit single-quoted SQL string literals for privileges and grantees instead of double-quoted identifiers.
  • Replace `priv_filter
map('tojson')withpriv_filter
Bump package version to 1.0.8 and document the grant SQL quoting fix.
  • Update changelog with v1.0.8 entry describing grant SQL quoting fix and version bump.
  • Update README displayed version from 1.0.7 to 1.0.8.
  • Update dbt_project.yml project version from 1.0.7 to 1.0.8.
CHANGELOG.md
README.md
dbt_project.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • You now repeat map("format", "'%s'") in several macros; consider extracting a small helper macro for building single-quoted IN lists to keep the quoting logic consistent and easier to adjust later.
  • The format("'%s'") approach assumes values never contain single quotes; if role or privilege names could include special characters, you may want to introduce a dedicated escaping/quoting helper to prevent malformed SQL.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You now repeat `map("format", "'%s'")` in several macros; consider extracting a small helper macro for building single-quoted IN lists to keep the quoting logic consistent and easier to adjust later.
- The `format("'%s'")` approach assumes values never contain single quotes; if role or privilege names could include special characters, you may want to introduce a dedicated escaping/quoting helper to prevent malformed SQL.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@jonhopper-dataengineers jonhopper-dataengineers merged commit 45b2f6c into main Jun 25, 2026
2 checks passed
@jonhopper-dataengineers jonhopper-dataengineers deleted the fix/grant-sql-quoting branch June 25, 2026 09:33
jonhopper-dataengineers added a commit that referenced this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant